import Vuex from 'vuex';
import Vue from 'vue';
// import middlewares from './middlewares';
import * as getters from './getters';
import * as actions from './actions';

Vue.use(Vuex);

// 定义单一状态树
const state = {
	topicTabs: [
		{
			name:'全部',
			ename:'all'
		},
		{
			name:'精华',
			ename:'good'
		},
		{
			name:'分享',
			ename:'share'
		},
		{
			name:'问答',
			ename:'ask'
		},
		{
			name:'招聘',
			ename:'job'
		}
	],
	hint: {
		show: true,
		colorRed: false,
		info: '正在加载中...'
	},
	topicLists:[],
	currentTab:'',
	currentPage:'',
	topic:''
};
//实际改变 状态(state) 的唯一方式是通过 提交(commit) 一个 mutation
const mutations = {
	// 获取文章列表
	FETCH_TOPIC_LISTS_SUCCESS(state,data) {
		state.hint.show = false;
		state.topicLists = data.data;
		state.currentTab = data.topicTab;
		state.currentPage = data.currentPage;
	},
	// 初始化加载
	INIT_HINT(state) {
		state.hint.show = false;
		state.hint.info = '正在加载中...';
	},
	// 显示加载中
	SHOW_HINT(state) {
		state.hint.show = true;
		state.hint.info = '正在加载中...';
	},
	FETCH_TOPIC_SUCCESS(state,topic){
		state.hint.show = false;
		state.topic = topic;
	}
};

export default new Vuex.Store({
  state,
  mutations,
  actions,
  getters,
  strict: process.env.NODE_ENV !== 'production',
  // middlewares
});